// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'dart:async';
import 'dart:io';

import 'package:bruno/bruno.dart';
import 'package:common/image/image_tools.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:path_provider/path_provider.dart';

import '../../world/world_audio_publish/waveforms_widget.dart';
import 'record/audio_card_record_logic.dart';
import 'record/audio_card_record_page.dart';
import 'record/audio_card_record_state.dart';

/// @description:
/// @author
/// @date: 2025-01-20 09:58:27
class AudioCardRecordRestultPage extends StatefulWidget {
  const AudioCardRecordRestultPage({Key? key}) : super(key: key);

  @override
  State<AudioCardRecordRestultPage> createState() => _AudioCardRecordRestultPageState();
}

class _AudioCardRecordRestultPageState extends State<AudioCardRecordRestultPage> {
  final AudioCardRecordLogic logic = Get.put(AudioCardRecordLogic());

  final AudioCardRecordState state = Get.find<AudioCardRecordLogic>().state;

  @override
  void initState() {
    super.initState();

    PermissionUtils.microphone();
  }

  Future<String> getAudiopath() async {
    Directory appDirectory = await getApplicationDocumentsDirectory();
    String audioPath = "${appDirectory.path}/recording.m4a";
    return audioPath;
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        SizedBox(
            width: double.infinity, child: Image.asset('assets/app/images/world/world_top_bg.png', fit: BoxFit.cover)),
        Scaffold(
          appBar: BrnAppBar(title: '声音卡片', backgroundColor: Colors.transparent),
          backgroundColor: Colors.transparent,
          body: Container(
            color: Colors.white,
            padding: EdgeInsets.only(
                bottom: MediaQuery.of(context).padding.bottom == 0 ? 10 : (MediaQuery.of(context).padding.bottom - 10)),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                Container(
                  height: 50.h,
                  padding: EdgeInsets.symmetric(horizontal: 10.w),
                  margin: EdgeInsets.symmetric(vertical: 6.w, horizontal: 20.5.w),
                  decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(25.r)), color: Colors.white),
                  child: Row(mainAxisAlignment: MainAxisAlignment.start, children: [
                    Image.asset('assets/app/images/world/audio_mic.png', width: 30.w),
                    Text('  用声音show自己，让Ta听见更好的你~', style: TextStyle(color: Colors.black, fontSize: 14.sp)),
                    SizedBox(width: 16.w),
                  ]),
                ),
                Container(
                  padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 20),
                  child: Stack(
                    children: [
                      Image.asset('assets/app/images/world/audio_play_bg.png'),
                      const Positioned(
                          top: 10,
                          left: 0,
                          right: 0,
                          child: Center(
                            child: WaveformsWidget(
                                width: 120,
                                waveformsHeight: 25,
                                bgColor: Color(0xFF3C9CF1),
                                radius: 30,
                                audioPath: '/data/user/0/com.tencent.flutter.tuikit/app_flutter/recording.m4a'),
                          )),
                      Positioned(
                          bottom: 20,
                          left: 0,
                          right: 0,
                          height: 40.h,
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceAround,
                            children: [
                              BrnSmallMainButton(
                                title: "删除声音",
                                width: 115.w,
                                fontWeight: FontWeight.w400,
                                textColor: const Color(0xFFF74437),
                                bgColor: const Color(0xFFFFFFFF),
                                themeData: BrnButtonConfig(
                                    smallButtonRadius: 255, smallButtonHeight: 45.h, smallButtonFontSize: 16.sp),
                                onTap: () {},
                              ),
                              BrnSmallMainButton(
                                title: "重新录制",
                                width: 115.w,
                                bgColor: const Color(0xFF25D4D0),
                                fontWeight: FontWeight.w400,
                                themeData: BrnButtonConfig(
                                    smallButtonRadius: 255, smallButtonHeight: 45.h, smallButtonFontSize: 16.sp),
                                onTap: () {
                                  Get.to(const AudioCardRecordPage());
                                },
                              )
                            ],
                          ))
                    ],
                  ),
                )
              ],
            ),
          ),
        ),
      ],
    );
  }
}
